//
//  BaseModel.m
//  摩登汽车
//
//  Created by king on 15/10/20.
//  Copyright © 2015年 king. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

+ (NSMutableArray *)baseModelByArr:(NSArray *)arr {
    // 先初始化容器arr
    NSMutableArray *modelArr = [NSMutableArray array];
    // 遍历数组
    for (NSDictionary *dic in arr) {
        @autoreleasepool {
            // 通过遍历的构造器来构造对象
            id model = [[self class] baseModelWithDic:dic];
            [modelArr addObject:model];
        }
    }
    return modelArr;
}

+ (instancetype)baseModelWithDic:(NSDictionary *)dic {
    // 通过多态创建对象
    id model = [[[self class] alloc] initWithDic:dic];
    return model;
}

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        // 进行kvc的赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

@end
